package com.taxi.apipassenger.config;


import com.taxi.apipassenger.myrule.TagLoadBalancer;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer;
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

/**
 * @Author: Ruomeng
 * @Date: 2024/12/15
 * @Description : online-taxi
 * 灰度发布 路由规则配置
 * @Version: 1.0
 */
public class TagLoadBalancerConfig {

    @Bean
    public ReactorLoadBalancer<ServiceInstance> reactorLoadBalancer(Environment environment, LoadBalancerClientFactory loadBalancerClientFactory) {
        String property = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME);
        return new TagLoadBalancer(property, loadBalancerClientFactory.getLazyProvider(property, ServiceInstanceListSupplier.class));
    }

}
